const express = require('express');
//1. 安装 cookie-parser
//2. 导入 cookie-parser 包
const cookieParser = require('cookie-parser');
const app = express();
//3. 设置中间件
app.use(cookieParser());

app.get('/', (request, response) => {
    response.end('home home home');
});

app.get('/set-cookie', (request, response) => {
    //4. 设置 cookie
    // Set-Cookie: username=zhangsan; Path=/
    // response.setHeader('Set-Cookie','username=zhangsan; Path=/')
    response.cookie('username','zhangsan');
    response.cookie('email','abc@qq.com', {maxAge: 600*1000});
    response.send('登录成功');
});

app.get('/get-cookie', (request, response) => {
    //获取报文中 cookie 的内容
    console.log(request.cookies);
    response.send('获取用户信息');
});

app.get('/clear-cookie', (request, response) => {
    //删除客户端浏览器中的某个 cookie
    response.clearCookie('username');
    response.clearCookie('BD_UPN');
    response.send('退出成功');
})


app.listen(80, () => {
    console.log('服务已经启动 80 端口监听中');
});